package net.xdclass.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import net.xdclass.interceptor.LoginInterceptor;
import net.xdclass.mapper.LinkGroupMapper;
import net.xdclass.model.LinkGroupDO;
import net.xdclass.request.LinkGroupAddRequest;
import net.xdclass.service.LinkGroupService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 小滴课堂,愿景：让技术不再难学
 *
 * @Description
 * @Author 二当家小D
 * @Remark 有问题直接联系我，源码-笔记-技术交流群
 * @Version 1.0
 **/
@Service
public class LinkGroupServiceImpl implements LinkGroupService {


    @Resource
    private LinkGroupMapper linkGroupMapper;
    @Override
    public int add(LinkGroupAddRequest addRequest) {

        long accountNo = LoginInterceptor.threadLocal.get().getAccountNo();
        LinkGroupDO linkGroupDO = new LinkGroupDO();
        linkGroupDO.setAccountNo(accountNo);
        linkGroupDO.setTitle(addRequest.getTitle());
        return linkGroupMapper.insert(linkGroupDO);
    }

    @Override
    public int del(Long groupId) {
        long accountNo = LoginInterceptor.threadLocal.get().getAccountNo();

//        linkGroupMapper.delete(Wrapp)
        LambdaQueryWrapper<LinkGroupDO> eq = Wrappers.lambdaQuery(LinkGroupDO.class)
                .eq(LinkGroupDO::getAccountNo, accountNo)
                .eq(LinkGroupDO::getId, groupId);
        return linkGroupMapper.delete(eq);

    }
}
